package app.TianQi;

import org.json.JSONObject;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import qiurank.Log;
import qiurank.PaFather;
import qiurank.PaHandle;
import qiurank.ThreadManage;

/**
 * Created by Administrator on 2016/1/13.
 */
public class TianQiHandle implements PaHandle {
    @Override
    public void handle(PaFather paFather, ThreadManage threadManage) {
        TianQiPa pa=(TianQiPa)paFather;
        Map<String,Object>rlmap=new HashMap<>();
        Map<String,Object> nrlmap=new HashMap<>();
        Map<String,Object> tomorrow=new HashMap<>();
        rlmap=pa.rljsonToMap();
        nrlmap=pa.nrljsonToMap();
        tomorrow=pa.tomorrowWeather();

        UrlManage urlManage=((UrlManage) pa.getUrlManage());
        WeatherModel weatherModel=urlManage.getWeatherModel();
        if(rlmap!=null){
            weatherModel.saveRelWeather(rlmap);
            rlmap.clear();
            rlmap=null;
        }
        if(nrlmap!=null){
            weatherModel.saveNRelWeather(nrlmap);
            nrlmap.clear();
            nrlmap=null;
        }
        if(tomorrow!=null){
            weatherModel.saveTomorrowWeather(tomorrow);
            tomorrow.clear();
            tomorrow=null;
        }

        //Log.console("待爬取数:"+urlManage.getNoUrlList().size()+",已爬取:"+urlManage.getYesUrlCount());
        if(urlManage.getNoUrlList().size()==0){
            threadManage.finishAllThread();
            threadManage.setFinish();
        }
        weatherModel=null;
        pa=null;


    }
}
